package com.hyt.it.ogt.ks.service.impl;

import java.time.LocalDateTime;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.hyt.core.base.BaseServiceImpl;
import com.hyt.core.util.UUIDUtils;
import com.hyt.it.ogt.ks.config.ConfigManager;
import com.hyt.it.ogt.ks.mapper.CollectLogMapper;
import com.hyt.it.ogt.ks.model.entity.CollectLog;
import com.hyt.it.ogt.ks.service.ICollectLogService;

import lombok.extern.slf4j.Slf4j;

/**
 * @author liuhh
 */
@Slf4j
@Service
public class CollectLogServiceImpl extends BaseServiceImpl<CollectLogMapper, CollectLog> implements ICollectLogService {
    @Resource
    private ConfigManager configManager;
    @Override
    public boolean save(CollectLog entity) {
        try {
            if (configManager.getLogActive()) {
                entity.setId(UUIDUtils.randomUUID());
                entity.setCreateDate(LocalDateTime.now());
                return super.save(entity);
            }
        } catch (Exception e) {
            log.error("保存异常日志时发生异常:{}", JSON.toJSONString(entity), e);
        }
        return true;
    }
}
